﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using VideoClipNameHelper;

namespace CheckClipNames
{
    class Program
    {
        private static string directoryOfInvalidFiles = ".INVALID_NAME";
        private static bool directoryOfInvalidFilesExists;
        private static bool isOnlyPrint = false;
        static void Main(string[] args)
        {
            //
            if(args.Length >0)
            {
                if (0 == string.Compare(args[0], "-OnlyPrint", true)) { isOnlyPrint = true; }
                else
                {
                    Console.WriteLine("Options:");
                    Console.WriteLine("-OnlyPrint : without moving files to directory");
                    return;
                }

            }
            //
            VideoClipData vcd = new VideoClipData();
            bool isGoodArtist = true;
            foreach (string f in Directory.EnumerateFiles(".", "*.mkv"))
            {
                string s = VideoClipNameHelper.VideoClipData.Parse(System.IO.Path.GetFileName(f), vcd);
                if ("" == s)
                {
                    //
                    isGoodArtist = true;
                    if (0 == vcd.Artists.Count)
                    {
                        isGoodArtist = VideoClipNameHelper.Articles.IsNameOKWithArticle(vcd.Artist);
                    }
                    else
                    {
                        foreach (string artist in vcd.Artists)
                        {
                            if (!VideoClipNameHelper.Articles.IsNameOKWithArticle(artist)) { isGoodArtist = false; break; }
                        }
                    }
                    //
                    if (isGoodArtist)
                    {
                        continue;
                    }
                }
                //
                string sOut = Path.GetFileName(f);
                if("" != s)
                {
                    sOut += (" =>" + s);
                }
                if(!isGoodArtist)
                {
                    sOut += (" => Artistname");
                }
                //
                Console.WriteLine(sOut);
                //
                if(!isOnlyPrint)MoveFileToSubdir(f);
                //
            }
        }

        private static bool MoveFileToSubdir(string f)
        {
            //
            if (!directoryOfInvalidFilesExists)
            {
                if (!Directory.Exists(directoryOfInvalidFiles)) Directory.CreateDirectory(directoryOfInvalidFiles);
                directoryOfInvalidFilesExists = true;
            }
            //
            Directory.Move(f, Path.Combine(directoryOfInvalidFiles, f));
            //
            return true;
        }

    
    
    }//class
}//namespace
